package com.yanfan.evaluation.controller;


import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.common.utils.SecurityUtils;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.evaluation.domain.InspectionReview;
import com.yanfan.evaluation.service.IInspectionReviewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 工单任务评价Controller
 *
 * @author kerwincui
 * @date 2024-08-06
 */
@Api(tags = "工单任务评价")
@RestController
@RequestMapping("/iot/review")
public class InspectionReviewController extends BaseController
{
    @Autowired
    private IInspectionReviewService inspectionReviewService;

    /**
     * 查询工单任务评价列表
     */
    @ApiOperation("工单任务评价分页列表")
    @PreAuthorize("@ss.hasPermi('iot:review:list')")
    @GetMapping("/list")
    public TableDataInfo list(InspectionReview inspectionReview)
    {
        startPage();
        List<InspectionReview> list = inspectionReviewService.selectInspectionReviewList(inspectionReview);
        return getDataTable(list);
    }

    @ApiOperation("查询工单任务评价")
    @PreAuthorize("@ss.hasPermi('iot:review:selectinspectionReview')")
    @GetMapping("selectinspectionReview")
    public AjaxResult selectinspectionReviewList(InspectionReview inspectionReview){
//        inspectionReview.setReviewer(SecurityUtils.getUsername());
        return success(inspectionReviewService.selectInspectionReview(inspectionReview));
    }

    /**
     * 导出工单任务评价列表
     */
    @ApiOperation("导出工单任务评价列表")
    @PreAuthorize("@ss.hasPermi('iot:review:export')")
    @Log(title = "工单任务评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionReview inspectionReview)
    {
        List<InspectionReview> list = inspectionReviewService.selectInspectionReviewList(inspectionReview);
        ExcelUtil<InspectionReview> util = new ExcelUtil<InspectionReview>(InspectionReview.class);
        util.exportExcel(response, list, "工单任务评价数据");
    }

    /**
     * 获取工单任务评价详细信息
     */
    @ApiOperation("获取工单任务评价详细信息")
    @PreAuthorize("@ss.hasPermi('iot:review:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(inspectionReviewService.selectInspectionReviewById(id));
    }

    /**
     * 新增工单任务评价
     */
    @ApiOperation("新增工单任务评价")
    @PreAuthorize("@ss.hasPermi('iot:review:add')")
    @Log(title = "工单任务评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InspectionReview inspectionReview)
    {
        String username = SecurityUtils.getUsername();
        inspectionReview.setReviewer(username);

        Date currentTime = new Date();
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yy-MM-dd");
        inspectionReview.setReviewTime(currentTime);
        return toAjax(inspectionReviewService.insertInspectionReview(inspectionReview));
    }

    /**
     * 修改工单任务评价
     */
    @ApiOperation("修改工单任务评价")
    @PreAuthorize("@ss.hasPermi('iot:review:edit')")
    @Log(title = "工单任务评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InspectionReview inspectionReview)
    {

        return toAjax(inspectionReviewService.updateInspectionReview(inspectionReview));
    }

    /**
     * 删除工单任务评价
     */
    @ApiOperation("删除工单任务评价")
    @PreAuthorize("@ss.hasPermi('iot:review:remove')")
    @Log(title = "工单任务评价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inspectionReviewService.deleteInspectionReviewByIds(ids));
    }
}
